﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;

namespace mediaPrime.Controls
{
    public class MPTileButton : Button
    {
        static MPTileButton()
        {
            // Use another default style than the base class
            FrameworkElement.DefaultStyleKeyProperty.OverrideMetadata(
                typeof(MPTileButton), new FrameworkPropertyMetadata(typeof(MPTileButton))
            );
        }

        protected override void OnPreviewKeyDown(System.Windows.Input.KeyEventArgs e)
        {
            if (e.Key == System.Windows.Input.Key.Enter)
            {
                this.IsPressed = true;
                e.Handled = true;
            }

            base.OnPreviewKeyDown(e);
        }

        protected override void OnPreviewKeyUp(System.Windows.Input.KeyEventArgs e)
        {
            if (e.Key == System.Windows.Input.Key.Enter && IsPressed)
            {
                this.IsPressed = false;
                e.Handled = true;
                OnClick();
            }
            base.OnPreviewKeyUp(e);
        }
    }
}
